﻿using System;
using System.ComponentModel;
using System.IO;
using System.Runtime.Serialization;

namespace HalconDotNet
{
	/// <summary>Represents an instance of a classifier.</summary>
	// Token: 0x02000020 RID: 32
	[Serializable]
	public class HClassBox : HHandle, ISerializable, ICloneable
	{
		// Token: 0x0600025F RID: 607 RVA: 0x0000F436 File Offset: 0x0000D636
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HClassBox(IntPtr handle) : base(handle)
		{
			this.AssertSemType();
		}

		// Token: 0x06000260 RID: 608 RVA: 0x0000F445 File Offset: 0x0000D645
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HClassBox(HHandle handle) : base(handle)
		{
			this.AssertSemType();
		}

		// Token: 0x06000261 RID: 609 RVA: 0x0000F454 File Offset: 0x0000D654
		private void AssertSemType()
		{
			base.AssertSemType("class_box");
		}

		// Token: 0x06000262 RID: 610 RVA: 0x0000F461 File Offset: 0x0000D661
		internal static int LoadNew(IntPtr proc, int parIndex, int err, out HClassBox obj)
		{
			obj = new HClassBox(HHandleBase.UNDEF);
			return obj.Load(proc, parIndex, err);
		}

		// Token: 0x06000263 RID: 611 RVA: 0x0000F47C File Offset: 0x0000D67C
		internal static int LoadNew(IntPtr proc, int parIndex, int err, out HClassBox[] obj)
		{
			HTuple htuple;
			err = HTuple.LoadNew(proc, parIndex, err, out htuple);
			obj = new HClassBox[htuple.Length];
			for (int i = 0; i < htuple.Length; i++)
			{
				obj[i] = new HClassBox(HalconAPI.IsLegacyHandleMode() ? htuple[i].IP : htuple[i].H);
			}
			htuple.Dispose();
			return err;
		}

		/// <summary>
		///   Create a new classifier.
		///   Modified instance represents: Handle of the classifier.
		/// </summary>
		// Token: 0x06000264 RID: 612 RVA: 0x0000F4EC File Offset: 0x0000D6EC
		public HClassBox()
		{
			IntPtr proc = HalconAPI.PreCall(1895);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		// Token: 0x06000265 RID: 613 RVA: 0x0000F530 File Offset: 0x0000D730
		void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
		{
			HSerializedItem hserializedItem = this.SerializeClassBox();
			byte[] value = hserializedItem;
			hserializedItem.Dispose();
			info.AddValue("data", value, typeof(byte[]));
		}

		// Token: 0x06000266 RID: 614 RVA: 0x0000F568 File Offset: 0x0000D768
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HClassBox(SerializationInfo info, StreamingContext context)
		{
			HSerializedItem hserializedItem = new HSerializedItem((byte[])info.GetValue("data", typeof(byte[])));
			this.DeserializeClassBox(hserializedItem);
			hserializedItem.Dispose();
		}

		/// <summary>Serialize object to binary stream in HALCON format</summary>
		// Token: 0x06000267 RID: 615 RVA: 0x0000F5A8 File Offset: 0x0000D7A8
		public new void Serialize(Stream stream)
		{
			HSerializedItem hserializedItem = this.SerializeClassBox();
			hserializedItem.Serialize(stream);
			hserializedItem.Dispose();
		}

		/// <summary>Deserialize object from binary stream in HALCON format</summary>
		// Token: 0x06000268 RID: 616 RVA: 0x0000F5BC File Offset: 0x0000D7BC
		public new static HClassBox Deserialize(Stream stream)
		{
			HClassBox hclassBox = new HClassBox();
			HSerializedItem hserializedItem = HSerializedItem.Deserialize(stream);
			hclassBox.DeserializeClassBox(hserializedItem);
			hserializedItem.Dispose();
			return hclassBox;
		}

		// Token: 0x06000269 RID: 617 RVA: 0x0000F5E2 File Offset: 0x0000D7E2
		object ICloneable.Clone()
		{
			return this.Clone();
		}

		// Token: 0x0600026A RID: 618 RVA: 0x0000F5EC File Offset: 0x0000D7EC
		public new HClassBox Clone()
		{
			HSerializedItem hserializedItem = this.SerializeClassBox();
			HClassBox hclassBox = new HClassBox();
			hclassBox.DeserializeClassBox(hserializedItem);
			hserializedItem.Dispose();
			return hclassBox;
		}

		/// <summary>
		///   Train a classificator using a multi-channel image.
		///   Instance represents: Handle of the classifier.
		/// </summary>
		/// <param name="foreground">Foreground pixels to be trained.</param>
		/// <param name="background">Background pixels to be trained (rejection class).</param>
		/// <param name="multiChannelImage">Multi-channel training image.</param>
		// Token: 0x0600026B RID: 619 RVA: 0x0000F614 File Offset: 0x0000D814
		public void LearnNdimBox(HRegion foreground, HRegion background, HImage multiChannelImage)
		{
			IntPtr proc = HalconAPI.PreCall(438);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, foreground);
			HalconAPI.Store(proc, 2, background);
			HalconAPI.Store(proc, 3, multiChannelImage);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
			GC.KeepAlive(foreground);
			GC.KeepAlive(background);
			GC.KeepAlive(multiChannelImage);
		}

		/// <summary>
		///   Classify pixels using hyper-cuboids.
		///   Instance represents: Handle of the classifier.
		/// </summary>
		/// <param name="multiChannelImage">Multi channel input image.</param>
		/// <returns>Classification result.</returns>
		// Token: 0x0600026C RID: 620 RVA: 0x0000F674 File Offset: 0x0000D874
		public HRegion ClassNdimBox(HImage multiChannelImage)
		{
			IntPtr proc = HalconAPI.PreCall(439);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, multiChannelImage);
			HalconAPI.InitOCT(proc, 1);
			int num = HalconAPI.CallProcedure(proc);
			HRegion result;
			num = HRegion.LoadNew(proc, 1, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			GC.KeepAlive(multiChannelImage);
			return result;
		}

		/// <summary>
		///   Deserialize a serialized classifier.
		///   Instance represents: Handle of the classifier.
		/// </summary>
		/// <param name="serializedItemHandle">Handle of the serialized item.</param>
		// Token: 0x0600026D RID: 621 RVA: 0x0000F6CC File Offset: 0x0000D8CC
		public void DeserializeClassBox(HSerializedItem serializedItemHandle)
		{
			IntPtr proc = HalconAPI.PreCall(1884);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, serializedItemHandle);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
			GC.KeepAlive(serializedItemHandle);
		}

		/// <summary>
		///   Serialize a classifier.
		///   Instance represents: Handle of the classifier.
		/// </summary>
		/// <returns>Handle of the serialized item.</returns>
		// Token: 0x0600026E RID: 622 RVA: 0x0000F710 File Offset: 0x0000D910
		public HSerializedItem SerializeClassBox()
		{
			IntPtr proc = HalconAPI.PreCall(1885);
			base.Store(proc, 0);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HSerializedItem result;
			num = HSerializedItem.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Save a classifier in a file.
		///   Instance represents: Handle of the classifier.
		/// </summary>
		/// <param name="fileName">Name of the file which contains the written data.</param>
		// Token: 0x0600026F RID: 623 RVA: 0x0000F758 File Offset: 0x0000D958
		public void WriteClassBox(string fileName)
		{
			IntPtr proc = HalconAPI.PreCall(1886);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, fileName);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Set system parameters for classification.
		///   Instance represents: Handle of the classifier.
		/// </summary>
		/// <param name="flag">Name of the wanted parameter. Default: "split_error"</param>
		/// <param name="value">Value of the parameter. Default: 0.1</param>
		// Token: 0x06000270 RID: 624 RVA: 0x0000F794 File Offset: 0x0000D994
		public void SetClassBoxParam(string flag, HTuple value)
		{
			IntPtr proc = HalconAPI.PreCall(1887);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, flag);
			HalconAPI.Store(proc, 2, value);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(value);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Set system parameters for classification.
		///   Instance represents: Handle of the classifier.
		/// </summary>
		/// <param name="flag">Name of the wanted parameter. Default: "split_error"</param>
		/// <param name="value">Value of the parameter. Default: 0.1</param>
		// Token: 0x06000271 RID: 625 RVA: 0x0000F7E0 File Offset: 0x0000D9E0
		public void SetClassBoxParam(string flag, double value)
		{
			IntPtr proc = HalconAPI.PreCall(1887);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, flag);
			HalconAPI.StoreD(proc, 2, value);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Read a classifier from a file.
		///   Instance represents: Handle of the classifier.
		/// </summary>
		/// <param name="fileName">Filename of the classifier.</param>
		// Token: 0x06000272 RID: 626 RVA: 0x0000F824 File Offset: 0x0000DA24
		public void ReadClassBox(string fileName)
		{
			IntPtr proc = HalconAPI.PreCall(1889);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, fileName);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Train the classifier with one data set.
		///   Instance represents: Handle of the classifier.
		/// </summary>
		/// <param name="sampKey">Number of the data set to train.</param>
		/// <param name="outfile">Name of the protocol file. Default: "training_prot"</param>
		/// <param name="NSamples">Number of arrays of attributes to learn. Default: 500</param>
		/// <param name="stopError">Classification error for termination. Default: 0.05</param>
		/// <param name="errorN">Error during the assignment. Default: 100</param>
		// Token: 0x06000273 RID: 627 RVA: 0x0000F860 File Offset: 0x0000DA60
		public void LearnSampsetBox(HFeatureSet sampKey, string outfile, int NSamples, double stopError, int errorN)
		{
			IntPtr proc = HalconAPI.PreCall(1890);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, sampKey);
			HalconAPI.StoreS(proc, 2, outfile);
			HalconAPI.StoreI(proc, 3, NSamples);
			HalconAPI.StoreD(proc, 4, stopError);
			HalconAPI.StoreI(proc, 5, errorN);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
			GC.KeepAlive(sampKey);
		}

		/// <summary>
		///   Train the classifier.
		///   Instance represents: Handle of the classifier.
		/// </summary>
		/// <param name="features">Array of attributes to learn. Default: [1.0,1.5,2.0]</param>
		/// <param name="classVal">Class to which the array has to be assigned. Default: 1</param>
		// Token: 0x06000274 RID: 628 RVA: 0x0000F8C4 File Offset: 0x0000DAC4
		public void LearnClassBox(HTuple features, int classVal)
		{
			IntPtr proc = HalconAPI.PreCall(1891);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, features);
			HalconAPI.StoreI(proc, 2, classVal);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(features);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Get information about the current parameter.
		///   Instance represents: Handle of the classifier.
		/// </summary>
		/// <param name="flag">Name of the system parameter. Default: "split_error"</param>
		/// <returns>Value of the system parameter.</returns>
		// Token: 0x06000275 RID: 629 RVA: 0x0000F910 File Offset: 0x0000DB10
		public HTuple GetClassBoxParam(string flag)
		{
			IntPtr proc = HalconAPI.PreCall(1892);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, flag);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Destroy the classifier.
		///   Instance represents: Handle of the classifier.
		/// </summary>
		// Token: 0x06000276 RID: 630 RVA: 0x0000F960 File Offset: 0x0000DB60
		public void CloseClassBox()
		{
			IntPtr proc = HalconAPI.PreCall(1894);
			base.Store(proc, 0);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Create a new classifier.
		///   Modified instance represents: Handle of the classifier.
		/// </summary>
		// Token: 0x06000277 RID: 631 RVA: 0x0000F994 File Offset: 0x0000DB94
		public void CreateClassBox()
		{
			this.Dispose();
			IntPtr proc = HalconAPI.PreCall(1895);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Describe the classes of a box classifier.
		///   Instance represents: Handle of the classifier.
		/// </summary>
		/// <param name="dimensions">Highest dimension for output. Default: 3</param>
		/// <param name="boxIdx">Indices of the boxes.</param>
		/// <param name="boxLowerBound">Lower bounds of the boxes (for each dimension).</param>
		/// <param name="boxHigherBound">Higher bounds of the boxes (for each dimension).</param>
		/// <param name="boxNumSamplesTrain">Number of training samples that were used to define this box (for each dimension).</param>
		/// <param name="boxNumSamplesWrong">Number of training samples that were assigned incorrectly to the box.</param>
		/// <returns>Indices of the classes.</returns>
		// Token: 0x06000278 RID: 632 RVA: 0x0000F9D8 File Offset: 0x0000DBD8
		public HTuple DescriptClassBox(int dimensions, out HTuple boxIdx, out HTuple boxLowerBound, out HTuple boxHigherBound, out HTuple boxNumSamplesTrain, out HTuple boxNumSamplesWrong)
		{
			IntPtr proc = HalconAPI.PreCall(1896);
			base.Store(proc, 0);
			HalconAPI.StoreI(proc, 1, dimensions);
			HalconAPI.InitOCT(proc, 0);
			HalconAPI.InitOCT(proc, 1);
			HalconAPI.InitOCT(proc, 2);
			HalconAPI.InitOCT(proc, 3);
			HalconAPI.InitOCT(proc, 4);
			HalconAPI.InitOCT(proc, 5);
			int num = HalconAPI.CallProcedure(proc);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, HTupleType.INTEGER, num, out result);
			num = HTuple.LoadNew(proc, 1, HTupleType.INTEGER, num, out boxIdx);
			num = HTuple.LoadNew(proc, 2, HTupleType.INTEGER, num, out boxLowerBound);
			num = HTuple.LoadNew(proc, 3, HTupleType.INTEGER, num, out boxHigherBound);
			num = HTuple.LoadNew(proc, 4, HTupleType.INTEGER, num, out boxNumSamplesTrain);
			num = HTuple.LoadNew(proc, 5, HTupleType.INTEGER, num, out boxNumSamplesWrong);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Describe the classes of a box classifier.
		///   Instance represents: Handle of the classifier.
		/// </summary>
		/// <param name="dimensions">Highest dimension for output. Default: 3</param>
		/// <param name="boxIdx">Indices of the boxes.</param>
		/// <param name="boxLowerBound">Lower bounds of the boxes (for each dimension).</param>
		/// <param name="boxHigherBound">Higher bounds of the boxes (for each dimension).</param>
		/// <param name="boxNumSamplesTrain">Number of training samples that were used to define this box (for each dimension).</param>
		/// <param name="boxNumSamplesWrong">Number of training samples that were assigned incorrectly to the box.</param>
		/// <returns>Indices of the classes.</returns>
		// Token: 0x06000279 RID: 633 RVA: 0x0000FA8C File Offset: 0x0000DC8C
		public int DescriptClassBox(int dimensions, out int boxIdx, out int boxLowerBound, out int boxHigherBound, out int boxNumSamplesTrain, out int boxNumSamplesWrong)
		{
			IntPtr proc = HalconAPI.PreCall(1896);
			base.Store(proc, 0);
			HalconAPI.StoreI(proc, 1, dimensions);
			HalconAPI.InitOCT(proc, 0);
			HalconAPI.InitOCT(proc, 1);
			HalconAPI.InitOCT(proc, 2);
			HalconAPI.InitOCT(proc, 3);
			HalconAPI.InitOCT(proc, 4);
			HalconAPI.InitOCT(proc, 5);
			int num = HalconAPI.CallProcedure(proc);
			int result;
			num = HalconAPI.LoadI(proc, 0, num, out result);
			num = HalconAPI.LoadI(proc, 1, num, out boxIdx);
			num = HalconAPI.LoadI(proc, 2, num, out boxLowerBound);
			num = HalconAPI.LoadI(proc, 3, num, out boxHigherBound);
			num = HalconAPI.LoadI(proc, 4, num, out boxNumSamplesTrain);
			num = HalconAPI.LoadI(proc, 5, num, out boxNumSamplesWrong);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Classify a set of arrays.
		///   Instance represents: Handle of the classifier.
		/// </summary>
		/// <param name="sampKey">Key of the test data.</param>
		/// <returns>Error during the assignment.</returns>
		// Token: 0x0600027A RID: 634 RVA: 0x0000FB3C File Offset: 0x0000DD3C
		public double TestSampsetBox(HFeatureSet sampKey)
		{
			IntPtr proc = HalconAPI.PreCall(1897);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, sampKey);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			double result;
			num = HalconAPI.LoadD(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			GC.KeepAlive(sampKey);
			return result;
		}

		/// <summary>
		///   Classify a tuple of attributes with rejection class.
		///   Instance represents: Handle of the classifier.
		/// </summary>
		/// <param name="featureList">Array of attributes which has to be classified. Default: 1.0</param>
		/// <returns>Number of the class, to which the array of attributes had been assigned or -1 for the rejection class.</returns>
		// Token: 0x0600027B RID: 635 RVA: 0x0000FB94 File Offset: 0x0000DD94
		public int EnquireRejectClassBox(HTuple featureList)
		{
			IntPtr proc = HalconAPI.PreCall(1898);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, featureList);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(featureList);
			int result;
			num = HalconAPI.LoadI(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Classify a tuple of attributes.
		///   Instance represents: Handle of the classifier.
		/// </summary>
		/// <param name="featureList">Array of attributes which has to be classified. Default: 1.0</param>
		/// <returns>Number of the class to which the array of attributes had been assigned.</returns>
		// Token: 0x0600027C RID: 636 RVA: 0x0000FBEC File Offset: 0x0000DDEC
		public int EnquireClassBox(HTuple featureList)
		{
			IntPtr proc = HalconAPI.PreCall(1899);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, featureList);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(featureList);
			int result;
			num = HalconAPI.LoadI(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}
	}
}
